<template>
  <div>
    <!-- 订阅提醒-->
    <div class="card_sub_wrapper" v-if="showSubWayMsg">
      <!-- 订阅方式组件 -->
      <div>
        <SubscribeWay @changeStatus="sebWayDialog"></SubscribeWay>
      </div>
      <!-- 订阅提醒信息展示组件 -->
      <SubMsgList />
    </div>
    <!-- 股池列表  -->
    <StockList />
    <!-- 个股订阅列表 -->
    <div>
      <Subscribe :isShow="isShow" @changeStatus="hideDialog"> </Subscribe>
    </div>
    <!-- 客服组件 -->
    <div class="card_wrapper">
      <CustomerService />
    </div>
  </div>
</template>
<script>
import CustomerService from '@/components/common/CustomerService';
import Subscribe from '@/components/common/Subscribe';
import StockList from '@/components/StockList';
import NoData from '@/components/common/NoData';
import SubscribeWay from '@/components/common/SubscribeWay';
import SubMsgList from '@/components/common/SubMsgList';
import { SUB_REM, SEND_MSG_QUERY, GET_SUB } from '@/apis';
import config from '@/config/index.js';
export default {
  name: 'Index',
  data() {
    return {
      //股池列表
      subscribeTips: [], //订阅提醒列表
      isLoading: false,
      btnGray: false,
      isShow: false,
      allStocks: [],
      showSubWayMsg: getParam('product') === 'jtzz',
    };
  },
  components: {
    CustomerService,
    NoData,
    Subscribe,
    SubscribeWay,
    SubMsgList,
    StockList,
  },
  computed: {
    //重新加载
    reload() {
      return this.$store.state.baseInfo.pushType;
    },
  },
  watch: {
    reload: {
      handler(newValue) {
        this.getAllStocks();
        this.$store.commit('setBaseInfo', { reload: '' });
      },
    },
  },
  mounted() {
    $(window).scrollTop(0);
    this.$pageStatus.loading();
    this.getAllStocks();
    // 页面埋点
    window.hxmPageStat({ id: config.stat.pageId, url_ver: config.stat.url_ver });
  },
  methods: {
    async getAllStocks() {
      let params = {};
      params.type = 3;
      params.version = getParam('product') === 'jtzz' ? 2 : 1;
      params.data = true;
      const res = await GET_SUB(params);
      if (Number(res.code) === 0 && res.data) {
        this.allStocks = res.data;
      }
    },
    sebWayDialog() {
      if (!this.allStocks.length && !this.$store.state.baseInfo.pushType) {
        this.$toast('请先订阅一个股池');
        return;
      }
      this.isShow = !this.isShow;
      this.$store.commit('setBaseInfo', { isShowSubWay: !this.$store.state.baseInfo.isShowSubWay });
    },
    hideDialog(arr) {
      this.isShow = arr.showStatus;
    },
  },
};
</script>
<style lang="less" scoped>
.card_sub_wrapper {
  position: relative;
  width: 7.42rem;
  font-size: 0.28rem;
  margin: 0 auto;
  background-color: #fff;
  padding-bottom: 10%;
}
[theme-mode='black'] .card_sub_wrapper {
  position: relative;
  width: 7.42rem;
  font-size: 0.28rem;
  margin: 0 auto;
  background-color: #1a1a1a;
  padding-bottom: 10%;
}
.card_wrapper {
  position: relative;
  width: 7.42rem;
  font-size: 0.28rem;
  margin: 0 auto;
}
[theme-mode='black'] .card_wrapper {
  position: relative;
  width: 7.42rem;
  font-size: 0.28rem;
  margin: 0 auto;
}
</style>
